﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Projectmanagement.Entity;
using Projectmanagement.Utl;

namespace Projectmanagement.Models
{
    public class _EmployeeLocal : EntityBase
    {
        [Display(Name = "权限名称"),Required]
        public int? RolePMID { get; set; }
        [Display(Name = "角色名"), Required]
        public int? EmployeeID { get; set; }
        [Display(Name = "角色名")]
        public string Name { get; set; }

        public string RoleName {
            get
            {
                var ep = CH.DB.RolePMs.Find(this.RolePMID);
                if (ep == null)
                    return "";
                return ep.Name;
            }
        }
        public string EmployeeName {
            get
            {
                if (string.IsNullOrEmpty(Name) == false)
                    return Name;
                var ep = CH.DBAccount.EmployeeRoles.Find(this.EmployeeID);
                if (ep == null)
                    return "";
                return ep.AccountName;
            }
        }

        public IEnumerable<SelectListItem> GetEmployeeSelectListItems()
        {
            var selectList = (from c in  CH.DBAccount.EmployeeRoles where c.IsActivated ==true select c).AsEnumerable().Select(a => new SelectListItem
            {
                Text = a.AccountName,
                Value = a.ID.ToString(),
                Selected = (a.ID == EmployeeID)
            }).OrderBy(o => o.Text);
            return selectList;
        }

        public IEnumerable<SelectListItem> GetRoleSelectListItems()
        {
            var selectList = (from a in  CH.DB.RolePMs  select a).AsEnumerable().Select(s=> new SelectListItem
            {
                Text = s.Name,
                Value = s.ID.ToString(),
                Selected = (s.ID == RolePMID)
            }).OrderBy(o=>o.Text);
            return selectList;
        }
    }
}